package com.yinlixian.frame.config.handler;

import com.yinlixian.frame.entity.ResultInfo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: GlobalExceptionHandler
 * @Description:
 * @author: yudm
 * @date: 2017-03-03 18:24
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultInfo<String> jsonErrorHandler(HttpServletRequest req, Exception e) throws Exception {
        ResultInfo<String> r = new ResultInfo<>();
        r.setMessage(e.getMessage());
        r.setResult(ResultInfo.Result.DefaultError);
//        r.setData("data");
        r.setUrl(req.getRequestURL().toString());
        return r;
    }
}
